﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<div class="panel panel-default" style="margin-bottom:0;">
    <div class="panel-heading navb-bg">
        住院退费查询
    </div>
    <div style="padding: 2px;padding-right:20px;">
        <table class="form" style="width:100%;">
            <tr>
                <td class="formTitle">住院号：</td>
                <td class="formValue">
                    <input id="zyh" type="text" class="form-control " placeholder="请输入住院号">
                </td>
                <td class="formTitle">病人姓名：</td>
                <td class="formValue">
                    <input class="form-control newtouch_Readonly" type="text" id="brxm" value="" />
                </td>

                <td class="formTitle">项目名称：</td>
                <td class="formValue">
                    <input class="form-control" type="text" id="sfxm" value="" />
                </td>
                <td class="formTitle">执行科室：</td>
                <td class="formValue">
                    <input class="form-control" type="text" id="zxks" value="" />
                </td>
                <td class="formTitle"></td>
                <td class="formValue" rowspan="2">
                    <button id="BtnQuery" class="btn btn btn-default btn-md dropdown-text" style="width:50px;">查询</button>
                </td>
            </tr>

        </table>
    </div>
</div>

<br />
<form id="tabGrid">
    <div class="gridPanel">
        <table id="refundGridList" rel="tabGrid"></table>
    </div>
    <br />
    <div class="panel panel-default" style="margin-bottom:0;">
        <div class="panel-heading navb-bg">
            退费
        </div>
        <div style="padding: 2px;padding-right:20px;">
            <table class="form" style="width:96%;" id="tslTable">
                <tr>
                    <td class="formTitle">退数量：</td>
                    <td class="formValue">
                        <input class="form-control" type="text" id="tsl" value="" />
                        <input class="form-control" type="hidden" id="bianhao" value="" />
                        <input class="form-control" type="hidden" id="IsYP" value="" />
                    </td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                </tr>
            </table>
        </div>
    </div>

    <br />
    <div class="gridPanel">
        <table id="gridListDetail" rel="tabGrid"></table>
    </div>
</form>
@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new[] { 4, 8 },
    F8Text = "提交"
})
<script>
    $(function () {
        //浏览器窗口调整大小时重新加载jqGrid的宽
        $(window).resize(function () {
            initLayout("tabGrid");
        });

        var txt_keyword = document.getElementById('zyh');
        txt_keyword.addEventListener('keydown', function (event) {
            event = event || window.event;
            if (event.keyCode == 13) {
                GetPatInfo();
            }
        });


        $("#detailTable").hide();

        initControl();
        gridListData([]);
        gridListDetail([]);
        $("#acc_reMoney").click(function () {
            newtouch_globalevent_f4();
            newtouch_event_f4();
        });


        $("#tuifeiQuery").click(function () {
            if (checkTSL()) {
                return false;
            }
        });
        $("#gridListDetail").children().children().click(function () {
            $(this).clone(true).appendTo($("#gridListDetail").children());//复制当前点击的节点，并将它追加到《ul》元素中，当添加参数时复制它的事件

        });
        function GetPatInfo() {
            var zyh = $("#zyh").val();
            $.najax({
                type: "POST",
                url: "@Url.Action("GetPatInfoByZyh")",
                data: {
                    zyh: zyh,
                    time: new Date()
                },
                cache: false,
                dataType: "json",
                success: function (ajaxresp) {
                    $("#brxm").val(ajaxresp.data);
                    $("#BtnQuery").click();
                },
                errorCallback: function (err) {
                },
                complete: function () {
                    isLoadingIIII = false;
                    $.loading(false);
                }
            });
        }
        $("#BtnQuery").click(function () {
            $('#gridListDetail').jqGrid("clearGridData");

            var zyh = $("#zyh").val();

            if (zyh.length > 0) {

                var brxm = $("#brxm").val();
                var yrh = $("#yrh").val();
                var zxks = $("#zxks").val();
                var xmmc = $("#sfxm").val();
                $.loading(true, "正在请求数据...");
                $.najax({
                    type: "POST",
                    url: "@Url.Action("BtnQuery")",
                    data: {
                        zyh: zyh,
                        brxm: brxm,
                        yrh: yrh,
                        zxks: zxks,
                        xmmc: xmmc
                    },
                    dataType: "json",
                    cache: false,
                    success: function (ajaxresp) {
                        $("#tslTable").css("display", "");
                        $('#refundGridList').jqGrid("clearGridData");
                        gridListData(ajaxresp.data);
                    },
                    errorCallback: function (err) {
                    },
                    complete: function () {
                        isLoadingIIII = false;
                        $.loading(false);
                    }
                });

            } else {
                $.modalAlert("住院号不能为空！", "error");
            }

        });

      
    });

      //点击退费返回退费结果
    function newtouch_event_f8() {
        if (checkTSL()) {
                $.modalConfirm("您确定要退费吗？", function (flag) {
                    if (flag) {
                        $.loading(true, "正在请求数据...");
                        $.najax({
                            type: "POST",
                            url: "@Url.Action("btnTuiFei")",
                            data: {
                                cxzyjfbbh: $("#bianhao").val(),
                                is_sfxm: $("#IsYP").val(),
                                refundNum: $("#tsl").val()

                            },
                            dataType: "json",
                            cache: false,
                            success: function (ajaxresp) {
                                $('#gridListDetail').jqGrid("clearGridData");
                                $.modalAlert("退费成功！", "success");
                                $("#BtnQuery").click();
                                $("#tsl").val(""); //退数量清空
                            },
                            error: function (err) {
                                $.loading(false)
                            },
                            complete: function () {
                                isLoadingIIII = false;
                                $.loading(false);
                            }
                        });
                        return true;
                    }
                }, false);
            }

    }
        function checkTSL() {
            var sl = $("#refundGridList").jqGridRowValue().SL;
            var tem = $("#tsl").val();
            if (parseInt(sl) < parseInt(tem)) {
                $.modalAlert("退数量不能大于交费数量！", "error");
                return false;
            }
            if (sl==undefined || tem == "" || parseInt(tem) < 0) {
                $.modalAlert("暂无可退数量！", "error");
                return false;
            }
            return true;

        }
        //加载当前选择的收费详细数据

        function GetDetail() {
            $.loading(true, "正在请求数据...");
            var data = $("#refundGridList").jqGridRowValue();

            $.najax({
                type: "GET",
                url: "@Url.Action("Detail")",
                data: {
                    zyh: data.ZYH,
                    xsebh: data.XSEBH,
                    sfxm: data.SFXM,
                    CreateTime: data.CreateTime,
                    is_sfxm: data.IS_SFXM
                },
                dataType: "json",
                cache: false,
                success: function (ajaxresp) {
                    $("#bianhao").val(ajaxresp.data[0].JFBBH);
                    $("#IsYP").val(data.IS_SFXM);
                    $('#gridListDetail').jqGrid("clearGridData");
                    gridListDetail(ajaxresp.data);
                    return;
                },
                errorCallback: function (err) {

                },
                complete: function () {
                    isLoadingIIII = false;
                    $.loading(false);
                }
            });
        }

        //收费列表单击事件
        function btn_selectrow() {
            $.loading(true, "正在请求数据...");
            var data = $("#refundGridList").jqGridRowValue();

            $.najax({
                type: "GET",
                url: "@Url.Action("Detail")",
                data: {
                    zyh: data.ZYH,
                    xsebh: data.XSEBH,
                    sfxmbh: data.SFXMBH,
                    CreateTime: data.CreateTime,
                    is_sfxm: data.IS_SFXM
                },
                dataType: "json",
                cache: false,
                success: function (ajaxresp) {
                    $("#bianhao").val(ajaxresp.data[0].JFBBH);
                    $("#IsYP").val(data.IS_SFXM);
                    $('#gridListDetail').jqGrid("clearGridData");
                    gridListDetail(ajaxresp.data);
                    return;

                },
                error: function (err) {
                    $.loading(false);
                },
                complete: function () {
                    isLoadingIIII = false;
                    $.loading(false);
                }
            });
        }


        function gridListDetail(mydata) {
            var $gridList = $("#gridListDetail");
            $gridList.dataNewGrid({
                height: 100,
                autowidth:false,
                width: $("#tabGrid").width() - 20,
                caption: "操作记录",
                colModel: [
                    { label: 'CXZYJFBBH', name: 'CXZYJFBBH', hidden: true, key: true },
                    { label: 'JFBBH', name: 'JFBBH', hidden: true, key: true },
                    {
                        label: '提档日期', name: 'CreateTime', width: 150, align: 'left'
                    },
                    { label: '项目名称', name: 'SFXMMC', width: 300, align: 'left' },
                    { label: '项目编号',name:'SFXMCode',hidden:true},
                    { label: '计费单位', name: 'JFDW', width: 100, align: 'left' },
                    { label: '数量', name: 'SL', width: 100, align: 'left' },
                    { label: '退数量', name: 'RETURN_SL', width: 100, align: 'left' }
                ], sortname: 'CreateTime asc'
            }, mydata);
            if (mydata.length > 0) {
                $('.ui-jqgrid-bdiv').find(".unwritten").remove();
            }
        }
        function gridListData(mydata) {
            var $gridList = $("#refundGridList");
            $gridList.dataNewGrid({
                height: 100,
                autowidth: false,
                width: $("#tabGrid").width() - 20,
                caption: "收费列表",
                colModel: [
                    { label: 'ZYH', name: 'ZYH', hidden: true, key: true },
                    { label: 'XSEBH', name: 'XSEBH', hidden: true, key: true },
                    { label: 'SFXM', name: 'SFXM', hidden: true, key: true },
                    { label: 'IS_SFXM', name: 'IS_SFXM', hidden: true, key: true },

                    {
                        label: '提档日期', name: 'CreateTime', width: 150, align: 'left'
                    },
                    { label: '项目名称', name: 'SFXMMC', width: 300, align: 'left' },
                    { label: '单位', name: 'JFDW', width: 100, align: 'left' },
                    { label: '数量', name: 'SL', width: 100, align: 'left' },
                    { label: '单价', name: 'DJ', width: 100, align: 'left' }

                ]
            }, mydata);
            if (mydata.length > 0) {
                $('.ui-jqgrid-bdiv').find(".unwritten").remove();
            }
        }
        function newtouch_event_f4() {
            $('#refundGridList').jqGrid("clearGridData");   //清除所有行
            $('#gridListDetail').jqGrid("clearGridData");
        }


        //加载收费项目，医生下拉框的值
        function initControl() {
            ///收费项目
            $("#sfxm").sfxmFloatingSelector({
                djDecimalPlaces: 4,
                ajaxparameters: function ($thisinput) {
                    return "dllb=1,2&mzzybz=1&keyword=" + $.trim($thisinput.val());
                },
                itemdbclickhandler: function ($thistr) {
                    $("#sfxm").val($thistr.attr("data-sfxmmc"));
                }
            });

            ///科室
            $("#zxks").newtouchBatchFloatingSelector({
                height: 170,
                width: 250,
                clickautotrigger: true,
                filter: function (keyword) {
                    //遍历数据源，用keyword来筛选出结果
                    var resultObjArr = new Array();
                    $.each(top.window.clients.sysDepartList, function (idx, val) {
                        if ((val.py && val.py.indexOf(keyword.toLowerCase()) >= 0)
                            || (val.Name && val.Name.indexOf(keyword) >= 0)
                            || keyword.trim() == "") {
                            resultObjArr.push(val);
                        }
                    });
                    return resultObjArr;
                },
                caption: "科室",
                colModel: [
                    { label: '编号', name: 'Code', widthratio: 50 },
                    { label: '名称', name: 'Name', widthratio: 20 },
                    { label: '拼音', name: 'py', hidden: true }
                ],
                itemdbclickhandler: function ($thistr) {
                    $("#zxks").attr("data-label", $thistr.find("td:eq(0)").html());
                    $("#zxks").val($thistr.find('td:eq(1)').html());
                    return;
                },
            });
        }
</script>
